import { getBaseInfo } from '@src/api/member'
import { noticeList } from '@src/api/loan'
import router from '@src/router'
Component({
  data: {
    list: [],
    queryPar:{
      pageSize:10,
      pageNum:1
    },
    hasMoreData:false
  },
  methods: {
    onLogin() {},
    onReady() {
      this.getAfficheList()
    },
    onPullDownRefresh() {
      wx.showNavigationBarLoading()
      wx.showLoading({
        title: '加载中...',
      })
      this.setData({ 'queryPar.page': 1, list: [], hasMoreData: false })
      this.getAfficheList()
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
      let { page } = this.data.queryPar
      if (this.data.hasMoreData) {
        return
      } else {
        page++
      }
      wx.showLoading({ title: '正在拼命加载' }) // 加载转圈显示
      const that = this
      that.setData({ onRefresh: true, 'queryPar.page': page }) // 累加数据
      this.getList()
    },
    getAfficheList() {
      setTimeout(() => {
        let {  queryPar, list } = this.data
        noticeList(queryPar).then((result) => {
          let { data: res } = result
          if (result.code == 0) {
            this.setData({ list: [...list, ...res.list] })
          }
          if (!res.hasNextPage) {
            this.setData({ hasMoreData: !res.hasNextPage })
          }
          wx.hideLoading()
          wx.hideNavigationBarLoading() //完成停止加载
          wx.stopPullDownRefresh() //停止下拉刷新
        })
      }, 1000)
    },
    toDetail(e) {
      let { item } = e.currentTarget.dataset
      router.push({
        name: 'loanmove/afficheDetail',
        params: { id: item.id },
      })
    },
  },
})
